package com.wen.design.entity.enums;

import com.wen.design.service.PayService;
import com.wen.design.service.impl.AliPayServiceImpl;
import com.wen.design.service.impl.WxPayServiceImpl;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.SneakyThrows;
@Getter
@AllArgsConstructor
public enum PayTypeEnum {
    ALI_PAY("ALI_PAY", "支付宝", AliPayServiceImpl.class.getName()),
    WX_PAY("WX_PAY", "微信", WxPayServiceImpl.class.getName()),
    ;
    private String type;
    private String description;
    private String className;
    public static PayTypeEnum getPayType(String type){
        for (PayTypeEnum payType: PayTypeEnum.values()) {
            if (payType.getType().equals(type)) {
                return payType;
            }
        }
        return null;
    }
    @SneakyThrows
    public PayService createInstance(){
        return (PayService) Class.forName(getClassName()).newInstance();
    }
}
